#include "cpu/exec.h"

make_EHelper(jr) {
    decinfo.width = 4;
    rtl_sr(id_dest->reg, pc, 4);
    rtl_add(&s0, &id_src->val, &id_src2->val);
    // Log("jump target is %x",s0);
    rtl_j(s0);
    difftest_skip_dut(1, 2);
}

make_EHelper(j) {
    decinfo.width = 4;
    rtl_sr(id_dest->reg, pc, 4);
    rtl_li(&s0,-4);
    rtl_add(&s1, pc, &s0);
    rtl_add(&s0, &s1, &id_src->val);
    // Log("jump target is %x",s0);
    rtl_j(s0);
}

make_EHelper(beq) {
    decinfo.width = 4;
    // rtl_sr(id_dest->reg, pc, 4);
    rtl_li(&s0,-4);
    rtl_add(&s1, pc, &s0);
    rtl_add(&s0, &s1, &id_dest->val);
    rtl_jrelop(RELOP_EQ,&id_src->val, &id_src2->val, s0);
}

make_EHelper(bne) {
    decinfo.width = 4;
    // rtl_sr(id_dest->reg, pc, 4);
    rtl_li(&s0,-4);
    rtl_add(&s1, pc, &s0);
    rtl_add(&s0, &s1, &id_dest->val);
    rtl_jrelop(RELOP_NE,&id_src->val, &id_src2->val, s0);
}

make_EHelper(blt) {
    decinfo.width = 4;
    // rtl_sr(id_dest->reg, pc, 4);
    rtl_li(&s0,-4);
    rtl_add(&s1, pc, &s0);
    rtl_add(&s0, &s1, &id_dest->val);
    rtl_jrelop(RELOP_LT,&id_src->val, &id_src2->val, s0);
}

make_EHelper(bge) {
    decinfo.width = 4;
    // rtl_sr(id_dest->reg, pc, 4);
    rtl_li(&s0,-4);
    rtl_add(&s1, pc, &s0);
    rtl_add(&s0, &s1, &id_dest->val);
    rtl_jrelop(RELOP_GE,&id_src->val, &id_src2->val, s0);
}

make_EHelper(bltu) {
    decinfo.width = 4;
    // rtl_sr(id_dest->reg, pc, 4);
    rtl_li(&s0,-4);
    rtl_add(&s1, pc, &s0);
    rtl_add(&s0, &s1, &id_dest->val);
    rtl_jrelop(RELOP_LTU,&id_src->val, &id_src2->val, s0);
}

make_EHelper(bgeu) {
    decinfo.width = 4;
    // rtl_sr(id_dest->reg, pc, 4);
    rtl_li(&s0,-4);
    rtl_add(&s1, pc, &s0);
    rtl_add(&s0, &s1, &id_dest->val);
    rtl_jrelop(RELOP_GEU,&id_src->val, &id_src2->val, s0);
}
